package com.ttc.ssm.service.admin.impl;

import com.ttc.ssm.common.CustomerPage;
import com.ttc.ssm.common.Page;
import com.ttc.ssm.mapper.admin.*;
import com.ttc.ssm.po.*;
import com.ttc.ssm.service.admin.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by 58296 on 2016/7/25.
 */
public class CustomerServiceImpl implements CustomerService{

    @Autowired
    CustomerMapper customerMapper;

    @Autowired
    ResumeMapper resumeMapper;

    @Autowired
    WorkExpMapper workExpMapper;

    @Autowired
    EducationMapper educationMapper;

    @Autowired
    CompetitionExpMapper competitionExpMapper;

    @Autowired
    SkillMapper skillMapper;

    @Override
    public List<Customer> getCustomerForPage(CustomerPage customerPage) throws Exception {
        return customerMapper.getCustomerForPage(customerPage);
    }

    @Override
    public int totalRows(Map where) throws Exception {
        return customerMapper.totalRows(where);
    }

    @Override
    public void updateCustomerById(Customer customer) throws Exception {
        if (customer == null) {
            System.out.println("内容不能为空!!!");
            return;
        }
        customerMapper.updateCustomerById(customer);
    }

    @Override
    public Customer getCustomerById(int customer_id) throws Exception {
        if (customer_id <= 0) {
            return  null;
        }
        return customerMapper.getCustomerById(customer_id);
    }

    @Override
    public void deleteCustomer(Map<String, Object> map) throws Exception {
        customerMapper.deleteCustomers(map);
    }

    @Override
    public void updateCustomerStatus(int company_id, int status) throws Exception {
        Date d = new Date();
        String s;
        java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        s = format1.format(d);
        System.out.println("=====================>"+s);
        customerMapper.updateCustomerStatus(company_id,status,s);
    }

    @Override
    public List<Resume> selectResumeForPage(CustomerPage page) throws Exception {
        return resumeMapper.selectResumeForPage(page);
    }

    @Override
    public int totalResumeRows(Map where) throws Exception {
        return resumeMapper.totalResumeRows(where);
    }

    @Override
    public void deleteResumes(Map<String, Object> map) throws Exception {
        workExpMapper.deleteWorkByResumeId(map);
        skillMapper.deleteSkillByResumeId(map);
        competitionExpMapper.deleteComByResumeId(map);
        educationMapper.deleteEduByResumeId(map);
        resumeMapper.deleteResumes(map);
    }

    @Override
    public Resume selectResumeById(Integer resume_id) throws Exception {
        return resumeMapper.selectResumeById(resume_id);
    }

    @Override
    public void updateResumes(Resume resume) throws Exception {
        resume.setDate_modified(new Date());
        resumeMapper.updateResume(resume);
    }

    @Override
    public List<Skill> selectSkillByResumeId(Integer resume_id) throws Exception {
        return skillMapper.selectSkillByResumeId(resume_id);
    }

    @Override
    public void deleteSkillById(Map<String,Object> map) throws Exception {
        skillMapper.deleteSkillById(map);
    }

    @Override
    public void insertSkill(Skill skill) throws Exception {
        skill.setDate_added(new Date());
        skillMapper.insertSkill(skill);
    }

    @Override
    public void updateSkill(Skill skill) throws Exception {
        skillMapper.updateSkill(skill);
    }

    @Override
    public List<Education> selectEduByResumeId(Integer resume_id) throws Exception {
        return educationMapper.selectEduByResumeId(resume_id);
    }

    @Override
    public void deleteEduById(Map<String,Object> map) throws Exception {
        educationMapper.deleteEduById(map);
    }

    @Override
    public void insertEdu(Education education) throws Exception {
        education.setDate_added(new Date());
        educationMapper.insertEdu(education);
    }

    @Override
    public void updateEdu(Education education) throws Exception {
        educationMapper.updateEdu(education);
    }

    @Override
    public List<CompetitionExp> selectComByResumeId(Integer resume_id) throws Exception {
        return competitionExpMapper.selectComByResumeId(resume_id);
    }

    @Override
    public void deleteComById(Map<String,Object> map) throws Exception {
        competitionExpMapper.deleteComById(map);
    }

    @Override
    public void insertCom(CompetitionExp competitionExp) throws Exception {
        competitionExp.setDate_added(new Date());
        competitionExpMapper.insertCom(competitionExp);
    }

    @Override
    public void updateCom(CompetitionExp competitionExp) throws Exception {
        competitionExpMapper.updateCom(competitionExp);
    }

    @Override
    public List<WorkExp> selectWorkByResumeId(Integer resume_id) throws Exception {
        return workExpMapper.selectWorkByResumeId(resume_id);
    }

    @Override
    public void deleteWorkById(Map<String,Object> map) throws Exception {
        workExpMapper.deleteWorkById(map);
    }

    @Override
    public void insertWork(WorkExp workExp) throws Exception {
        workExp.setDate_added(new Date());
        workExpMapper.insertWork(workExp);
    }

    @Override
    public void updateWork(WorkExp workExp) throws Exception {
        workExpMapper.updateWork(workExp);
    }
}
